<?php


namespace lib;

use app\api\model\AdvanceAiLog;
use super\Http;

class LibAdvanceAiInApi
{
    private static $appId = 'com.indian.indianproject';
    private static $sdkKey = '0922b2fa29b8841d';
    private static $secretKey = '38d3119f988a7061';

    /**
     * 获取鉴权信息
     * @return mixed
     */
    public function authLicense()
    {
        $url = 'https://in-api.advance.ai/in/openapi/face-identity/v1/auth-license';
        $params = [
            'licenseEffectiveSeconds' => 600,
            'applicationId' => self::$appId,
        ];
        $res = Http::send_post($url, $params, ['X-ADVAI-KEY: ' . self::$sdkKey, 'Content-Type: application/json; charset=utf-8']);

        return json_decode($res, true);
    }

    /**
     * 获取检测分数
     * @param $livenessId
     */
    public function getLivenessDetection($livenessId)
    {
        $url = 'https://in-api.advance.ai/in/openapi/face-identity/v1/liveness-detection';
        $params = [
            'livenessId' => $livenessId,
            'resultType' => 'IMAGE_URL',
        ];
        $res = Http::send_post($url, $params, ['X-ADVAI-KEY: ' . self::$sdkKey, 'Content-Type: application/json; charset=utf-8']);
        $data = json_decode($res, true);
        $setLogData = [
            'name' => '获取活体认证检测分数',
            'url' => $url,
            'send_json' => json_encode($params),
            'result_json' => $res,
            'code' => $data['code']
        ];
        AdvanceAiLog::create($setLogData);
        return $data;
    }
}